<template>
  <div>
      <van-row class="backg login">

        <van-col span="24">
          <h4>欢迎登陆</h4>
          <h6>登陆后可享受更多操作哟</h6>
        </van-col>

        <van-col span="24">
          <van-form @submit="onSubmit">
            <van-field
                v-model="username"
                name="用户名"
                label="用户名"
                placeholder="用户名"
                :rules="[{ required: true, message: '请填写用户名' }]"
            />
            <van-field
                v-model="password"
                type="password"
                name="密码"
                label="密码"
                placeholder="密码"
                :rules="[{ required: true, message: '请填写密码' }]"
            />
            <div style="margin: 16px;">
              <van-button round block type="info" native-type="submit">
                提交
              </van-button>
              <router-link to="" class="font-12">忘记密码</router-link>
            </div>
          </van-form>
        </van-col>
      </van-row>
  </div>
</template>

<script>

import {Toast} from "vant";
import md5 from 'js-md5';
export default {
  data() {
    return {
      username: '',
      password: '',
    };
  },
  created(){
    if (localStorage.getItem("userId")!=null){
      this.$router.push('/Work');
    }

  },
  methods: {
    onSubmit(values) {
      console.log("value值")
      console.log(values)
      this.$http.post('http://139.224.226.216:8083/app/applogin?userName='+values.用户名+'&password='+md5(values.用户名+values.密码))
          .then(res=>{
            console.log(res);
            if (res.data.code==500){
              Toast("账号或密码错误！");
            }else if (res.data.code==0){
              // Toast("登陆成功！");
              // sessionStorage.setItem("userId",res.data.data.userId);
              localStorage.setItem("userId",res.data.data.userId);
              localStorage.setItem("uuid",res.data.data.deptUuid);
              localStorage.setItem("userName",res.data.data.userName);
              localStorage.setItem("avatar",res.data.data.avatar);
              localStorage.setItem("deptName",res.data.data.deptName);
              localStorage.setItem("userType",res.data.data.userType);
              this.$router.push('/Work');
            }else{
              Toast("非法操作！");
            }

          })
          .catch(err=>{
            Toast("网络错误"+err);
          });


    },
  },
};
</script>

<style scoped>

</style>